from dajax.core import Dajax

from django.template.loader import render_to_string
from devnote.app.models import *

from django.contrib.auth.models import User
from devnote.app.models import Category, Entity

# def form_test(request):
    # form_test = TestForm()
    
    # render = render_to_string('app/test.html', {'form_test': form_test})
    
    # dajax = Dajax()
    # dajax.assign('#tmp', 'innerHTML', render)
    # return dajax.json()

def get_data_all(request):
    
    active_notes = Entity.objects.filter(user=request.user,type='N',state='ACV',important=True)
    archived_notes = Entity.objects.filter(user=request.user,type='N',state='ARH')
    edt_note_title_form = EditNoteTitleForm()
    edt_note_importance_form = EditNoteImportanceForm()
    edt_note_priority_form = EditNotePriorityForm()
    edt_note_description_form = EditNoteDescriptionForm()
    edt_note_type_form = EditNoteTypeForm()
    arh_note_form = ArchiveNoteForm()
    del_note_form = DeleteNoteForm()
    add_note_form = AddNoteForm()
    res_note_form = RestoreNoteForm()
    
    render = render_to_string('app/notes.html',
           { 'active_notes': active_notes,
             'archived_notes': archived_notes,
             'edt_note_title_form': edt_note_title_form,
             'edt_note_importance_form': edt_note_importance_form,
             'edt_note_priority_form': edt_note_priority_form,
             'edt_note_description_form': edt_note_description_form,
             'edt_note_type_form': edt_note_type_form,
             'arh_note_form': arh_note_form,
             'del_note_form': del_note_form,
             'add_note_form': add_note_form,
             'res_note_form': res_note_form })
    
    dajax = Dajax()
    dajax.assign('.data', 'innerHTML', render)
    return dajax.json()

def get_data_important(request):
    print 'IMPORTANT'

def get_data_by_priority(request, p):
    print p, request.user


    # active_notes = get_notes(request.user, 'ACV')
    # archived_notes = get_notes(request.user, 'ARH')
    # edt_note_title_form = EditNoteTitleForm()
    # edt_note_importance_form = EditNoteImportanceForm()
    # edt_note_priority_form = EditNotePriorityForm()
    # edt_note_description_form = EditNoteDescriptionForm()
    # edt_note_type_form = EditNoteTypeForm()
    # arh_note_form = ArchiveNoteForm()
    # del_note_form = DeleteNoteForm()
    # add_note_form = AddNoteForm()
    # res_note_form = RestoreNoteForm()

    # 'active_notes': active_notes,
    # 'archived_notes': archived_notes,
    # 'edt_note_title_form': edt_note_title_form,
    # 'edt_note_importance_form': edt_note_importance_form,
    # 'edt_note_priority_form': edt_note_priority_form,
    # 'edt_note_description_form': edt_note_description_form,
    # 'edt_note_type_form': edt_note_type_form,
    # 'arh_note_form': arh_note_form,
    # 'del_note_form': del_note_form,
    # 'add_note_form': add_note_form,
    # 'res_note_form': res_note_form,
